package com.example.keli.ui.center;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.utils.DataUtil;
import com.example.keli.base.utils.GlideUtil;

import java.util.List;

/**
 * description $desc$
 * created by jerry on 2019/3/18.
 */
public class ActiveAdapter extends BaseQuickAdapter<ActivieList.DataBean, BaseViewHolder> {

    private Context mContext;
//    int width = 173 * 2;
//    int height = 220 * 2;
//    RelativeLayout.LayoutParams layoutParams;
    //    "1待启动", "2报名中", "3进行中", "4已结束"
    private int mStatus;

    public ActiveAdapter(List<ActivieList.DataBean> mData, Context context, int status) {
        super(R.layout.item_active, mData);
        this.mContext = context;
        this.mStatus = status;
//        width = (ScreenUtil.getScreenWidth(context) - DensityUtil.dip2px(context, 24));
//        height = width * 150 / 351;
//        layoutParams = new RelativeLayout.LayoutParams(width,height);
    }

    @Override
    protected void convert(BaseViewHolder helper, ActivieList.DataBean dataBean) {
        TextView tv_sign = helper.getView(R.id.tv_sign);
        if ("true".equals(dataBean.getIsSign())){
//            tv_sign.setBackground(null);
            Drawable drawable=mContext.getResources().getDrawable(R.color.white);
            tv_sign.setBackground(drawable);
//            tv_sign.setBackgroundColor(Color.argb(0,0,0,0));
            tv_sign.setTextColor(mContext.getResources().getColor(R.color.text_color));
            tv_sign.setText("已参与");
        }else {
            Drawable drawable = mContext.getResources().getDrawable(R.drawable.shape_text_background);
            tv_sign.setBackground(drawable);
            tv_sign.setText("我要报名");
        }

        if (mStatus == 4){
            tv_sign.setBackground(null);
            tv_sign.setTextColor(mContext.getResources().getColor(R.color.text_color));
            tv_sign.setText("已结束");
        }
        helper.setText(R.id.tv_title, dataBean.getTitle());
        helper.setText(R.id.tv_num, String.format("参与人数:  %s%s", dataBean.getEnrollCount(), "人"));
        helper.setText(R.id.tv_endtime, String.format("结束时间:  %s", DataUtil.getData(dataBean.getEnd_time())));
        ImageView imageView = helper.getView(R.id.iv_active);

        GlideUtil.displayRound(mContext, imageView, dataBean.getCover_picture(), 3);
//        imageView.setLayoutParams(layoutParams);
    }
}
